﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Rhino.Commons;
using Rhino.Security.Interfaces;
using DomainModel.Abstract;
using Rhino.Security.Model;

namespace WebUI.Models.Forms
{
    public class PermissionsForm
    {
        //public SelectList ddlGroupName { get; set; }
        //public ICollection<Operation> availableOps { get; set; }

        public bool opHomeIndex { get; set; }
        public bool opProductsList { get; set; }

        public PermissionsForm()
        {
            using (UnitOfWork.Start())
            {
                var guest = IoC.Resolve<IUserRepository>().GetUser("guest");
                var authorizationService = IoC.Resolve<IAuthorizationService>();

                opHomeIndex = authorizationService.IsAllowed(guest, "/Home/Index");
                opProductsList = authorizationService.IsAllowed(guest, "/Products/List");
                
            }
        }

        //using(UnitOfWork.Start())
        //{
        //    string GroupsQuery = "select groups from UsersGroup groups";
        //    ICollection<UsersGroup> availableGroups =
        //        UnitOfWork.CurrentSession.CreateQuery(GroupsQuery).List<UsersGroup>();
        //    ddlGroupName = new SelectList(availableGroups, "groupId", "groupName");


        //    string OpsQuery = "select ops from Operation ops";
        //    availableOps =
        //        UnitOfWork.CurrentSession.CreateQuery(OpsQuery).List<Operation>(); 

        //}
    }
}
